local canxu = fk.CreateSkill{
  name = "plum__canxu",
}

Fk:loadTranslationTable{
  [canxu.name] = "掺虚",
  [":"..canxu.name] = "每轮限一次，一名角色的回合开始时，你可以指定两名角色，"
  .."前者的【杀】于本回合内视为【杀/闪/影】，后者的【桃】和【酒】于本回合内视为【桃/酒/影】，"
  .."有角色使用基本牌时，本回合移去“/”左侧的相同牌名。",

  ["#plum__canxu-prompt"] = "掺虚：可以指定两名角色，前者的【杀】于本回合内视为【杀/闪/影】，后者的【桃】和【酒】于本回合内视为【桃/酒/影】",
  ["#plum__canxu_log"] = "掺虚：%from %arg",

  ["#plum__canxu_front"] = "的【杀】于本回合内视为【杀/闪/影】",
  ["#plum__canxu_later"] = "的【桃】和【酒】于本回合内视为【桃/酒/影】",
}

---@param target ServerPlayer
---@param after boolean?
local doCanxu = function (target, after)
  local room = target.room
  local from_name, to_name
  if not after then
    from_name = {"slash"}
    to_name = {"slash", "jink", "shade"}
  else
    from_name = {"peach", "analeptic"}
    to_name = {"peach", "analeptic", "shade"}
  end
  room:setPlayerMark(target, "canxu_viewas-turn", {from_name, to_name})
  room:handleAddLoseSkills(target, "plum__canxu_viewas&")
end

canxu:addEffect(fk.TurnStart, {
  anim_type = "control",
  max_round_use_times = 1,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(canxu.name) and player:usedSkillTimes(canxu.name, Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = room:getAlivePlayers(false),
      min_num = 2,
      max_num = 2,
      skill_name = canxu.name,
      cancelable = true,
      prompt = "#plum__canxu-prompt",
    })
    if #tos == 2 then
      event:setCostData(self, tos)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local tos = event:getCostData(self) ---@type ServerPlayer[]
    local room = player.room
    room:sendLog { type = "#plum__canxu_log", from = tos[1].id, arg = "#plum__canxu_front", toast = true, }
    room:sendLog { type = "#plum__canxu_log", from = tos[2].id, arg = "#plum__canxu_later", toast = true, }

    room:addSkill("#plum__canxu_prohibit")
    room:addSkill("#plum__canxu_refresh")
    doCanxu(tos[1])
    doCanxu(tos[2], true)
  end
})

return canxu